package com.hotel.project.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hotel.project.demo.dao.hotel.HotelAnswerDao;
import com.hotel.project.demo.dao.hotel.HotelQuestionDao;
import com.hotel.project.demo.domain.HotelAnswerEntity;
import com.hotel.project.demo.domain.HotelQuestionEntity;
import com.hotel.project.demo.service.HotelQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class HotelQuestionServiceImpl extends CurdServiceImpl<HotelQuestionEntity> implements HotelQuestionService {

    @Autowired
    private HotelQuestionDao hotelQuestionDao;

    @Autowired
    private HotelAnswerDao hotelAnswerDao;


    @Override
    public List<HotelQuestionEntity> listHotelQuestionEntityByHotelId(Long hotelId) {
        LambdaQueryWrapper<HotelQuestionEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(HotelQuestionEntity::getUserId,hotelId);
        wrapper.eq(HotelQuestionEntity::getDeleted,0);
        List<HotelQuestionEntity> list = list(wrapper);
        return list;
    }

    @Override
    public List<HotelQuestionEntity> listHotelQuestionEntityByUserId(Long userId) {
        LambdaQueryWrapper<HotelQuestionEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(HotelQuestionEntity::getUserId,userId);
        wrapper.eq(HotelQuestionEntity::getDeleted,0);
        List<HotelQuestionEntity> list = list(wrapper);
        return list;
    }

    @Override
    public List<HotelQuestionEntity> listHotelQuestionEntityByAskUserId(Long userId, Integer status) {
        LambdaQueryWrapper<HotelAnswerEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(HotelAnswerEntity::getUserId, userId);
        wrapper.eq(HotelAnswerEntity::getDeleted,status);
        List<HotelAnswerEntity> answerList = hotelAnswerDao.selectList(wrapper);
        List<HotelQuestionEntity> list = new ArrayList<>();
        if (answerList != null && answerList.size() > 0){
            answerList.forEach(hotelAnswerEntity -> {
                list.add(getById(hotelAnswerEntity.getQuestionId()));
            });
        }
        return list;
    }
}
